package com.dwjm.exam.stu_login;


import com.dwjm.exam.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class StudentLoginHandler extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码方式
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //获取浏览器传递进来的参数，登录账号和密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        //将拿到的account和password传递给dao层，进行登录验证
        StudentLoginDao studentLoginDao = new StudentLoginDaoImpl();
        boolean login_result = studentLoginDao.login(username, password);
        if (login_result){
            resp.getWriter().write("Y");
        }else{
            resp.getWriter().write("N");
        }

    }
}
